//===============================================================================
// Microsoft patterns & practices
// Guidance Explorer Offline Client
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================



using System.Windows.Forms;

namespace GuidanceExplorer.Model
{    
    public class Column
    {
        #region Static Part

        /// <summary>
        /// Factory.
        /// </summary>
        /// <returns></returns>
        public static Column New()
        {
            return new Column();
        }

        #endregion

        #region Private members

        /// <summary>
        /// The source value this column will show.
        /// </summary>
        private string _source;

        /// <summary>
        /// The caption of the column
        /// </summary>
        private string _caption;

        /// <summary>
        /// The sort order for this column
        /// </summary>
        private SortOrder _sort;

        /// <summary>
        /// The visibility for this column.
        /// </summary>
        private bool _visible;

        /// <summary>
        /// The width for this column
        /// </summary>
        private int _width;

        /// <summary>
        /// The field definition for this column.
        /// </summary>
        private Field _field;

        /// <summary>
        /// The filter set in the list view.
        /// </summary>
        private string _autoFilter;

        /// <summary>
        /// The field's position in the list view
        /// </summary>
        private int _position = -1;

        /// <summary>
        /// The field's original position in the list view
        /// </summary>
        private int _originalPosition = -1;

        #endregion

        #region Constructor

        /// <summary>
        /// Default private constructor.
        /// </summary>
        /// 
        protected Column() { }

        #endregion

        #region Public Properties
        public bool Editable { get; set; }
        /// <summary>
        /// The source value this column will show.
        /// </summary>
        public string Source
        {
            get { return _source; }
            set { _source = value; }
        }

        /// <summary>
        /// The caption of the column
        /// </summary>
        public string Caption
        {
            get { return _caption; }
            set { _caption = value; }
        }

        /// <summary>
        /// The sort order for this column
        /// </summary>
        public SortOrder Sort
        {
            get { return _sort; }
            set { _sort = value; }
        }

        /// <summary>
        /// The visibility for this column.
        /// </summary>
        public bool Visible
        {
            get { return _visible; }
            set { _visible = value; }
        }

        /// <summary>
        /// The width for this column
        /// </summary>
        public int Width
        {
            get { return _width; }
            set { _width = value; }
        }

        /// <summary>
        /// The field definition for this column.
        /// </summary>
        public Field Field
        {
            get { return _field; }
            set { _field = value; }
        }

        /// <summary>
        /// Get/set the field's position in the list view
        /// </summary>
        public virtual int Position
        {
            get { return _position; }
            set 
            {
                _position = value;

                if (_originalPosition == -1)
                {
                    _originalPosition = value;
                }
            }
        }

        /// <summary>
        /// Get/set the field's original position in the list view
        /// </summary>
        public int OriginalPosition
        {
            get { return _originalPosition; }
        }

        /// <summary>
        /// The filter set in the list view.
        /// </summary>
        public string AutoFilter
        {
            get { return _autoFilter; }
            set { _autoFilter = value; }
        }

        #endregion

        public override bool Equals(object obj)
        {
            Column other = obj as Column;
            if (other != null)
            {
                bool caption = (this._caption == other._caption);
                bool sort = (this._sort == other._sort);
                bool source = (this._source == other._source);
                bool visible = (this._visible == other._visible);
                bool width = (this._width == other._width);
                return (caption && sort && source && visible && width );
            }
            else
            {
                return base.Equals(obj);
            }
        }

        public override int GetHashCode()
        {
            return _source.GetHashCode();
        }
    }
}

